home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvitovdu32 / src / pascal / vt100vdu.p < prev    next >
Text File  |  1991-11-10  |  6KB  |  198 lines

  1. (* VDU routines for a VT100 terminal. *)
  2.  
  3. #include 'globals.h';
  4. #include 'screenio.h';
  5. #include 'vdu.h';
  6.  
  7. VAR cursrow, curscol : INTEGER;   (* ShowChar remembers cursor location *)
  8.  
  9. (******************************************************************************)
  10.  
  11. PROCEDURE StartText;
  12.  
  13. (* We are about to draw text in dialogue region. *)
  14.  
  15. BEGIN
  16. (* VT100 treats text and graphics the same, so do nothing *)
  17. END; (* StartText *)
  18.  
  19. (******************************************************************************)
  20.  
  21. PROCEDURE MoveAbs (row, col : INTEGER);
  22.  
  23. (* Move cursor to given screen position. *)
  24.  
  25. BEGIN
  26. WriteChar(ESC); WriteChar('[');
  27. WriteInt(row);
  28. WriteChar(';');
  29. WriteInt(col);
  30. WriteChar('H');
  31. END; (* MoveAbs *)
  32.  
  33. (******************************************************************************)
  34.  
  35. PROCEDURE MoveToTextLine (line : INTEGER);
  36.  
  37. (* Move current position to start of given line. *)
  38.  
  39. BEGIN
  40. MoveAbs(line,1);
  41. END; (* MoveToTextLine *)
  42.  
  43. (******************************************************************************)
  44.  
  45. PROCEDURE ClearTextLine (line : INTEGER);
  46.  
  47. (* Erase given line; note that DVItoVDU does not assume anything about the
  48.    current position at the end of this routine.
  49. *)
  50.  
  51. BEGIN
  52. MoveAbs(line,1);
  53. WriteChar(ESC);
  54. WriteString('[K');   (* erase to end of line *)
  55. END; (* ClearTextLine *)
  56.  
  57. (******************************************************************************)
  58.  
  59. PROCEDURE ClearScreen;
  60.  
  61. BEGIN
  62. WriteChar(ESC);
  63. WriteString('[2J');   (* erase entire screen *)
  64. END; (* ClearScreen *)
  65.  
  66. (******************************************************************************)
  67.  
  68. PROCEDURE StartGraphics;
  69.  
  70. (* We are about to draw in window region.
  71.    VT100 makes no distinction between text and graphics.
  72.    All we do is reset the current cursor position to some undefined state for
  73.    use in the next ShowChar call.
  74. *)
  75.  
  76. BEGIN
  77. cursrow := 0;
  78. END; (* StartGraphics *)
  79.  
  80. (******************************************************************************)
  81.  
  82. PROCEDURE LoadFont (fontname : string;
  83.                     fontsize : INTEGER;
  84.                     mag, hscale, vscale : REAL);
  85.  
  86. BEGIN
  87. (* only one character size available on VT100s, so do nothing *)
  88. END; (* LoadFont *)
  89.  
  90. (******************************************************************************)
  91.  
  92. PROCEDURE ShowChar (screenh, screenv : INTEGER;
  93.                     ch : CHAR);
  94.  
  95. (* Show the given Terse character (mapped to ASCII) at the given position.
  96.    We remember the cursor position (cursrow,curscol) so we can reduce the
  97.    output bytes needed to position the next Terse character.
  98.    StartGraphics resets the position to an undefined state (cursrow = 0).
  99.    We also reset when the cursor reaches the right edge (= windowwd) to
  100.    avoid possibility of any auto wrap.
  101. *)
  102.  
  103. VAR amount : INTEGER;
  104.  
  105. BEGIN
  106. (* first translate DVItoVDU coordinates into actual screen location *)
  107. screenh := screenh + 1;
  108. screenv := screenv + 1;
  109. IF cursrow = screenv THEN BEGIN
  110.    (* The cursor is on the same line as in previous ShowChar call so we only
  111.       need to move left or right, and probably just a small amount (if at all).
  112.    *)
  113.    IF screenh = curscol THEN       (* cursor in correct location *)
  114.       curscol := curscol + 1       (* cursor will move right when ch written *)
  115.    ELSE IF screenh < curscol THEN BEGIN      (* move cursor left *)
  116.       amount := curscol - screenh;
  117.       WriteChar(ESC); WriteChar('[');
  118.       IF amount > 1 THEN BEGIN               (* default is 1 col *)
  119.          WriteInt(amount);
  120.          curscol := curscol - (amount-1);    (* no need if amount = 1 *)
  121.       END;
  122.       WriteChar('D');
  123.    END
  124.    ELSE BEGIN                                (* move cursor right *)
  125.       amount := screenh - curscol;
  126.       WriteChar(ESC); WriteChar('[');
  127.       IF amount > 1 THEN WriteInt(amount);   (* default is 1 col *)
  128.       curscol := curscol + (amount+1);
  129.       WriteChar('C');
  130.    END;
  131. END
  132. ELSE BEGIN                         (* cursrow undefined or ch on a new line *)
  133.    MoveAbs(screenv,screenh);
  134.    cursrow := screenv;
  135.    curscol := screenh + 1;         (* cursor will move right when ch written *)
  136. END;
  137. IF screenh = windowwd THEN         (* ch will be written at right edge *)
  138.    cursrow := 0;                   (* so avoid auto wrap next time around *)
  139. WriteChar(TeXtoASCII[ch]);
  140. END; (* ShowChar *)
  141.  
  142. (******************************************************************************)
  143.  
  144. PROCEDURE ShowRectangle (screenh, screenv,          (* top left pixel *)
  145.                          width, height : INTEGER;   (* size of rectangle *)
  146.                          ch : CHAR);                (* black pixel *)
  147.  
  148. (* Display the given rectangle using the given black pixel character.
  149.    DVItoVDU ensures the entire rectangle is visible.
  150. *)
  151.  
  152. VAR i, j : INTEGER;
  153.  
  154. BEGIN
  155. ch := TeXtoASCII[ch];            (* first convert TeX ch to ASCII *)
  156. screenh := screenh + 1;
  157. FOR i := 1 TO height DO BEGIN    (* adding 1 to screenv here *)
  158.    MoveAbs(screenv+i,screenh);   (* move cursor to start of next row *)
  159.    FOR j := 1 TO width DO
  160.       WriteChar(ch);
  161. END;
  162. END; (* ShowRectangle *)
  163.  
  164. (******************************************************************************)
  165.  
  166. PROCEDURE ResetVDU;
  167.  
  168. BEGIN
  169. (* no need to do anything *)
  170. END; (* ResetVDU *)
  171.  
  172. (******************************************************************************)
  173.  
  174. PROCEDURE InitVDU;
  175.  
  176. (* The main program only calls this routine after it has parsed the command
  177.    line and successfully opened the given DVI file.
  178. *)
  179.  
  180. CONST
  181.    (* On a VT100 a "pixel" is a character. *)
  182.    screenwd = 80;   (* width of VT100 screen in pixels *)
  183.    screenht = 24;   (* height of VT100 screen in pixels *)
  184.    lineht   = 1;    (* height of one text line in pixels *)
  185.  
  186. BEGIN
  187. (* initialize the VDU parameters *)
  188. DVIstatusl    := 1;
  189. windowstatusl := 2;
  190. messagel      := 3;
  191. commandl      := 4;
  192. bottoml       := screenht DIV lineht;   (* = number of text lines *)
  193. windowh       := 0;
  194. windowv       := 4 * lineht;
  195. windowwd      := screenwd;
  196. windowht      := screenht - (4 * lineht);
  197. END; (* InitVDU *)
  198.